﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Plugin;
using WinFormsContentLoading;
using WinFormsGraphicsDevice;
using StandardFramework;
using DependencyInjection;
using WeifenLuo.WinFormsUI.Docking;
using PolarExpress.View.Interfaces;
using PolarExpress.Model.Interfaces;

namespace PolarExpress.View
{
    public partial class FrmSceneView : DockContent, ISceneView
    {
        IProject _project;

        [Inject]
        public FrmSceneView(IProject project)
        {
            InitializeComponent();

            _project = project;

            sceneControl1.ComponentPool = _project.ComponentPool;
            sceneControl1.AllowDrop = true;
            sceneControl1.DragEnter += new DragEventHandler(sceneControl1_DragEnter);
            sceneControl1.DragDrop += new DragEventHandler(sceneControl1_DragDrop);
        }

        void FrmScene_DragDrop(object sender, DragEventArgs e)
        {
            throw new NotImplementedException();
        }

        void sceneControl1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(Plugin.Plugin)))
            {
                e.Effect = DragDropEffects.Copy;
            }
        }

        void sceneControl1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(Plugin.Plugin)))
            {
                Plugin.Plugin plugin = (Plugin.Plugin)e.Data.GetData(typeof(Plugin.Plugin));

                Point pClient = this.PointToClient(new Point(e.X, e.Y));

                OnComponentDragDrop(plugin, pClient.X, pClient.Y);
            }
        }

        public event PluginHandler ComponentDragDrop;

        public void OnComponentDragDrop(Plugin.Plugin plugin, int x, int y)
        {
            if (ComponentDragDrop != null)
            {
                ComponentDragDrop(new PluginEventArgs(plugin, x, y));
            }
        }
    }
}
